<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Three-table example</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="sdodasrel.examples.two-table.html">Two-table examples</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="sdodasrel.limitations.html">Limitations</a></div>
 <div class="up"><a href="sdodasrel.examples.html">范例</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="sdodasrel.examples.three-table" class="section">
  <h2 class="title">Three-table example</h2>
  <p class="para">
   The following examples use all three tables from the company database: 
   the company, department, and employee tables. These introduce the final 
   piece of function not exercised by the examples above: the 
   non-containment reference
   <var class="varname"><var class="varname">employee_of_the_month</var></var>.
  </p>
  <p class="para">
   Like the examples above for company and department, this set of examples 
   is intended to illustrate the full lifecycle of such a data graph.
  </p>


  <p class="para">
   <div class="example" id="example-5355">
    <p><strong>Example #1 One company, one department, one employee - Create</strong></p>
    <div class="example-contents"><p>
     In this example a company is created containing one department and 
     just one employee. Note that this example clears out all three tables 
     at the start so that the exact results of the queries can be known.
    </p></div>
    <div class="example-contents"><p>
     Note how once the company, department and employee have been created, 
     the
     <var class="varname"><var class="varname">employee_of_the_month</var></var>
     property of the company can be made to point at the new employee.
     As this is a non-containment reference, this cannot be done until 
     the employee object has been created within the graph.
     Non-containment references need to be managed carefully.
     For example if the employee were now deleted from under the department, 
     it would not be correct to try to save the graph without
     first clearing or re-assigning the
     <var class="varname"><var class="varname">employee_of_the_month</var></var>
     property.
     The closure rule for SDO data graphs requires that any object pointed 
     at by a non-containment reference must also be reachable by 
     containment relationships.
    </p></div>
    <div class="example-contents"><p>
     When it comes to inserting the graph into the database, the procedure 
     is similar to the example of inserting the company and department,
     but
     <var class="varname"><var class="varname">employee_of_the_month</var></var>
     introduces an extra complexity.
     The Relational DAS needs to insert the objects working down the tree 
     formed by containment relationships, so company, then department, then 
     employee. This is necessary so that it always has the auto-generated 
     primary key of a parent on hand to include in a child row. But when 
     the company row is inserted the employee who is employee of the month 
     has not yet been inserted and the primary key is not known. The 
     procedure is that after the employee record is inserted and its 
     primary key known, a final step is performed in which the 
     company record is updated with the employee&#039;s primary key.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">require_once&nbsp;</span><span style="color: #DD0000">'SDO/DAS/Relational.php'</span><span style="color: #007700">;<br />require_once&nbsp;</span><span style="color: #DD0000">'company_metadata.inc.php'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/*************************************************************************************<br />*&nbsp;Empty&nbsp;out&nbsp;the&nbsp;three&nbsp;tables<br />*************************************************************************************/<br /></span><span style="color: #0000BB">$dbh&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">PDO</span><span style="color: #007700">(</span><span style="color: #0000BB">PDO_DSN</span><span style="color: #007700">,</span><span style="color: #0000BB">DATABASE_USER</span><span style="color: #007700">,</span><span style="color: #0000BB">DATABASE_PASSWORD</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$pdo_stmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$dbh</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">prepare</span><span style="color: #007700">(</span><span style="color: #DD0000">'DELETE&nbsp;FROM&nbsp;COMPANY;'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$rows_affected&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$pdo_stmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">execute</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$pdo_stmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$dbh</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">prepare</span><span style="color: #007700">(</span><span style="color: #DD0000">'DELETE&nbsp;FROM&nbsp;DEPARTMENT;'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$rows_affected&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$pdo_stmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">execute</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$pdo_stmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$dbh</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">prepare</span><span style="color: #007700">(</span><span style="color: #DD0000">'DELETE&nbsp;FROM&nbsp;EMPLOYEE;'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$rows_affected&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$pdo_stmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">execute</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/*************************************************************************************<br />*&nbsp;Create&nbsp;a&nbsp;tiny&nbsp;but&nbsp;complete&nbsp;company.<br />*&nbsp;The&nbsp;company&nbsp;name&nbsp;is&nbsp;Acme.<br />*&nbsp;There&nbsp;is&nbsp;one&nbsp;department,&nbsp;Shoe.<br />*&nbsp;There&nbsp;is&nbsp;one&nbsp;employee,&nbsp;Sue.<br />*&nbsp;The&nbsp;employee&nbsp;of&nbsp;the&nbsp;month&nbsp;is&nbsp;Sue.<br />*************************************************************************************/<br /></span><span style="color: #0000BB">$das&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SDO_DAS_Relational&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">$database_metadata</span><span style="color: #007700">,</span><span style="color: #DD0000">'company'</span><span style="color: #007700">,</span><span style="color: #0000BB">$SDO_containment_metadata</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$dbh&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">PDO</span><span style="color: #007700">(</span><span style="color: #0000BB">PDO_DSN</span><span style="color: #007700">,</span><span style="color: #0000BB">DATABASE_USER</span><span style="color: #007700">,</span><span style="color: #0000BB">DATABASE_PASSWORD</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$das&nbsp;&nbsp;</span><span style="color: #007700">-&gt;&nbsp;</span><span style="color: #0000BB">createRootDataObject</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$acme&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$root&nbsp;</span><span style="color: #007700">-&gt;&nbsp;</span><span style="color: #0000BB">createDataObject</span><span style="color: #007700">(</span><span style="color: #DD0000">'company'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$acme&nbsp;</span><span style="color: #007700">-&gt;&nbsp;</span><span style="color: #0000BB">name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Acme"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$shoe&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$acme&nbsp;</span><span style="color: #007700">-&gt;&nbsp;</span><span style="color: #0000BB">createDataObject</span><span style="color: #007700">(</span><span style="color: #DD0000">'department'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$shoe&nbsp;</span><span style="color: #007700">-&gt;&nbsp;</span><span style="color: #0000BB">name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'Shoe'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$shoe&nbsp;</span><span style="color: #007700">-&gt;&nbsp;</span><span style="color: #0000BB">location&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'A-block'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$sue&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$shoe&nbsp;</span><span style="color: #007700">-&gt;&nbsp;</span><span style="color: #0000BB">createDataObject</span><span style="color: #007700">(</span><span style="color: #DD0000">'employee'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$sue&nbsp;</span><span style="color: #007700">-&gt;&nbsp;</span><span style="color: #0000BB">name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'Sue'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$acme&nbsp;</span><span style="color: #007700">-&gt;&nbsp;</span><span style="color: #0000BB">employee_of_the_month&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$sue</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$das&nbsp;</span><span style="color: #007700">-&gt;&nbsp;</span><span style="color: #0000BB">applyChanges</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbh</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$root</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #DD0000">"Wrote&nbsp;back&nbsp;Acme&nbsp;with&nbsp;one&nbsp;department&nbsp;and&nbsp;one&nbsp;employee\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>

  <p class="para">
   <div class="example" id="example-5356">
    <p><strong>Example #2 One company, one department, one employee - Retrieve and update</strong></p>
    <div class="example-contents"><p>
     The SQL statement passed to the Relational DAS is this time an inner 
     join that retrieves data from all three tables. Otherwise this example 
     introduces nothing that has not appeared in a previous example. 
    </p></div>
    <div class="example-contents"><p>
     The graph is updated by the addition of a new department and employee 
     and some alterations to the name properties of the existing objects 
     in the graph. The combined changes are then written back. The 
     Relational DAS will process and apply an arbitrary mixture of 
     additions, modifications and deletions to and from the data graph.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">require_once&nbsp;</span><span style="color: #DD0000">'SDO/DAS/Relational.php'</span><span style="color: #007700">;<br />require_once&nbsp;</span><span style="color: #DD0000">'company_metadata.inc.php'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/*************************************************************************************<br />*&nbsp;Find&nbsp;the&nbsp;company&nbsp;again&nbsp;and&nbsp;change&nbsp;various&nbsp;aspects.<br />*&nbsp;Change&nbsp;the&nbsp;name&nbsp;of&nbsp;the&nbsp;company,&nbsp;department&nbsp;and&nbsp;employee.<br />*&nbsp;Add&nbsp;a&nbsp;second&nbsp;department&nbsp;and&nbsp;a&nbsp;new&nbsp;employee.<br />*&nbsp;Change&nbsp;the&nbsp;employee&nbsp;of&nbsp;the&nbsp;month.<br />*************************************************************************************/<br /></span><span style="color: #0000BB">$das&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SDO_DAS_Relational&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">$database_metadata</span><span style="color: #007700">,</span><span style="color: #DD0000">'company'</span><span style="color: #007700">,</span><span style="color: #0000BB">$SDO_containment_metadata</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$dbh&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">PDO</span><span style="color: #007700">(</span><span style="color: #0000BB">PDO_DSN</span><span style="color: #007700">,</span><span style="color: #0000BB">DATABASE_USER</span><span style="color: #007700">,</span><span style="color: #0000BB">DATABASE_PASSWORD</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$root&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$das</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">executeQuery</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbh</span><span style="color: #007700">,<br />&nbsp;&nbsp;</span><span style="color: #DD0000">"select&nbsp;c.id,&nbsp;c.name,&nbsp;c.employee_of_the_month,&nbsp;d.id,&nbsp;d.name,&nbsp;e.id,&nbsp;e.name&nbsp;"&nbsp;</span><span style="color: #007700">.<br />&nbsp;&nbsp;</span><span style="color: #DD0000">"from&nbsp;company&nbsp;c,&nbsp;department&nbsp;d,&nbsp;employee&nbsp;e&nbsp;"&nbsp;</span><span style="color: #007700">.<br />&nbsp;&nbsp;</span><span style="color: #DD0000">"where&nbsp;e.dept_id&nbsp;=&nbsp;d.id&nbsp;and&nbsp;d.co_id&nbsp;=&nbsp;c.id&nbsp;and&nbsp;c.name='Acme'"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;array(</span><span style="color: #DD0000">'company.id'</span><span style="color: #007700">,</span><span style="color: #DD0000">'company.name'</span><span style="color: #007700">,</span><span style="color: #DD0000">'company.employee_of_the_month'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'department.id'</span><span style="color: #007700">,</span><span style="color: #DD0000">'department.name'</span><span style="color: #007700">,</span><span style="color: #DD0000">'employee.id'</span><span style="color: #007700">,</span><span style="color: #DD0000">'employee.name'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$acme&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$root</span><span style="color: #007700">[</span><span style="color: #DD0000">'company'</span><span style="color: #007700">][</span><span style="color: #0000BB">0</span><span style="color: #007700">];<br /><br /></span><span style="color: #0000BB">$shoe&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$acme</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">department</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">];<br /></span><span style="color: #0000BB">$sue&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$shoe&nbsp;</span><span style="color: #007700">-&gt;&nbsp;</span><span style="color: #0000BB">employee</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">];<br /><br /></span><span style="color: #0000BB">$it&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$acme</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">createDataObject</span><span style="color: #007700">(</span><span style="color: #DD0000">'department'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$it</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'IT'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$it</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">location&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'G-block'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$billy&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$it</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">createDataObject</span><span style="color: #007700">(</span><span style="color: #DD0000">'employee'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$billy</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">name&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'Billy'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$acme</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">name&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'MegaCorp'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$shoe</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">name&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'Footwear'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$sue</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">name&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'Susan'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$acme</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">employee_of_the_month&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$billy</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$das&nbsp;</span><span style="color: #007700">-&gt;&nbsp;</span><span style="color: #0000BB">applyChanges</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbh</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$root</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">"Wrote&nbsp;back&nbsp;company&nbsp;with&nbsp;extra&nbsp;department&nbsp;and&nbsp;employee&nbsp;and&nbsp;all&nbsp;the&nbsp;names&nbsp;changed&nbsp;(Megacorp/Footwear/Susan)\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>

  <p class="para">
   <div class="example" id="example-5357">
    <p><strong>Example #3 One company, two departments, two employees - Retrieve and delete</strong></p>
    <div class="example-contents"><p>
     The company is retrieved as a complete data graph containing five 
     data objects - the company, two departments and two employees.
     They are all deleted by deleting the company object. Deleting an 
     object from the graph deletes all the object beneath it in the graph.
     Five SQL DELETE statements will be generated and  executed. As always 
     they will be qualified with a WHERE clause that contains all of the 
     fields that were retrieved, so that any updates to the data in the 
     database in the meantime by another process will be detected.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">require_once&nbsp;</span><span style="color: #DD0000">'SDO/DAS/Relational.php'</span><span style="color: #007700">;<br />require_once&nbsp;</span><span style="color: #DD0000">'company_metadata.inc.php'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/*************************************************************************************<br />*&nbsp;Now&nbsp;read&nbsp;it&nbsp;one&nbsp;more&nbsp;time&nbsp;and&nbsp;delete&nbsp;it.<br />*&nbsp;You&nbsp;can&nbsp;delete&nbsp;part,&nbsp;apply&nbsp;the&nbsp;changes,&nbsp;then&nbsp;carry&nbsp;on&nbsp;working&nbsp;with&nbsp;the&nbsp;same&nbsp;graph&nbsp;but<br />*&nbsp;care&nbsp;is&nbsp;needed&nbsp;to&nbsp;keep&nbsp;closure&nbsp;-&nbsp;you&nbsp;cannot&nbsp;delete&nbsp;the&nbsp;employee&nbsp;who&nbsp;is&nbsp;eotm&nbsp;without<br />*&nbsp;reassigning.&nbsp;For&nbsp;safety&nbsp;here&nbsp;we&nbsp;delete&nbsp;the&nbsp;company&nbsp;all&nbsp;in&nbsp;one&nbsp;go.&nbsp;<br />*************************************************************************************/<br /></span><span style="color: #0000BB">$das&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SDO_DAS_Relational&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">$database_metadata</span><span style="color: #007700">,</span><span style="color: #DD0000">'company'</span><span style="color: #007700">,</span><span style="color: #0000BB">$SDO_containment_metadata</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$dbh&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">PDO</span><span style="color: #007700">(</span><span style="color: #0000BB">PDO_DSN</span><span style="color: #007700">,</span><span style="color: #0000BB">DATABASE_USER</span><span style="color: #007700">,</span><span style="color: #0000BB">DATABASE_PASSWORD</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$root&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$das</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">executeQuery</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbh</span><span style="color: #007700">,<br />&nbsp;&nbsp;</span><span style="color: #DD0000">"select&nbsp;c.id,&nbsp;c.name,&nbsp;c.employee_of_the_month,&nbsp;d.id,&nbsp;d.name,&nbsp;e.id,&nbsp;e.name&nbsp;"&nbsp;</span><span style="color: #007700">.<br />&nbsp;&nbsp;</span><span style="color: #DD0000">"from&nbsp;company&nbsp;c,&nbsp;department&nbsp;d,&nbsp;employee&nbsp;e&nbsp;"&nbsp;</span><span style="color: #007700">.<br />&nbsp;&nbsp;</span><span style="color: #DD0000">"where&nbsp;e.dept_id&nbsp;=&nbsp;d.id&nbsp;and&nbsp;d.co_id&nbsp;=&nbsp;c.id&nbsp;and&nbsp;c.name='MegaCorp';"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;array(</span><span style="color: #DD0000">'company.id'</span><span style="color: #007700">,</span><span style="color: #DD0000">'company.name'</span><span style="color: #007700">,</span><span style="color: #DD0000">'company.employee_of_the_month'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'department.id'</span><span style="color: #007700">,</span><span style="color: #DD0000">'department.name'</span><span style="color: #007700">,</span><span style="color: #DD0000">'employee.id'</span><span style="color: #007700">,</span><span style="color: #DD0000">'employee.name'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$megacorp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$root</span><span style="color: #007700">[</span><span style="color: #DD0000">'company'</span><span style="color: #007700">][</span><span style="color: #0000BB">0</span><span style="color: #007700">];<br /><br />unset(</span><span style="color: #0000BB">$root</span><span style="color: #007700">[</span><span style="color: #DD0000">'company'</span><span style="color: #007700">]);<br /></span><span style="color: #0000BB">$das&nbsp;</span><span style="color: #007700">-&gt;&nbsp;</span><span style="color: #0000BB">applyChanges</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbh</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$root</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #DD0000">"Deleted&nbsp;the&nbsp;company,&nbsp;departments&nbsp;and&nbsp;employees&nbsp;all&nbsp;in&nbsp;one&nbsp;go.\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="sdodasrel.examples.two-table.html">Two-table examples</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="sdodasrel.limitations.html">Limitations</a></div>
 <div class="up"><a href="sdodasrel.examples.html">范例</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
